package net.zjitc.arrays.tree;

public class MyBTree<E> {
    TreeNode<E> root;

    public MyBTree(TreeNode<E> root) {
        this.root = root;
    }

    public void setRoot(TreeNode<E> root) {
        this.root = root;
    }

    public void insertL(TreeNode<E> node, E data) {
        if (node.left != null) {
            throw new RuntimeException("左子树已经存在");
        }
        node.left = new TreeNode<E>(data);
    }

    public void insertR(TreeNode<E> node, E data) {
        if (node.right != null) {
            throw new RuntimeException("右子树已经存在");
        }
        node.right = new TreeNode<E>(data);
    }

    public TreeNode<E> getLChild(TreeNode<E> node) {
        return node.left;
    }

    public TreeNode<E> getRChild(TreeNode<E> node) {
        return node.right;
    }

    public TreeNode<E> getRoot() {
        return root;
    }

    public void preOrder(TreeNode<E> node) {
        if (node != null) {
            //根
            System.out.println(node.data);
            //左
            preOrder(node.left);
            //右
            preOrder(node.right);
        }

    }

    public void inOrder(TreeNode<E> node) {
        if (node != null) {
            //左
            preOrder(node.left);
            //根
            System.out.println(node.data);
            //右
            preOrder(node.right);
        }
    }
    public void postOrder(TreeNode<E> node) {
        if (node != null) {
            //左
            preOrder(node.left);
            //右
            preOrder(node.right);
            //根
            System.out.println(node.data);
        }
    }
        public void traversal(int type){
        switch (type){

        }
        }
}
